/**
 * 库存模块类型定义
 */

/**
 * 表格操作按钮点击回调类型
 */
export interface ActionClickParams {
  code: string;
  row: any;
}

export type OnActionClickFn = (params: ActionClickParams) => void;

/**
 * 仓库类型定义
 */
export interface Warehouse {
  warehouse_id: string;
  warehouse_name: string;
  warehouse_code: string;
  [key: string]: any;
}

/**
 * 库位类型定义
 */
export interface Location {
  location_id: string;
  location_name: string;
  location_code: string;
  [key: string]: any;
}

/**
 * 库存状态类型
 */
export type InventoryStatus = 'excess' | 'normal' | 'shortage' | 'warning';

/**
 * 物料类型定义
 */
export type MaterialType =
  | 'auxiliary_material'
  | 'finished_product'
  | 'other'
  | 'raw_material'
  | 'semi_finished'
  | 'tool';

/**
 * 库存调整类型
 */
export type AdjustType = 'adjust_in' | 'adjust_out';

/**
 * 库存交易类型定义
 */
export type TransactionType =
  | 'adjustment'
  | 'check'
  | 'inbound'
  | 'outbound'
  | 'transfer';

/**
 * 库存数据类型
 */
export interface Inventory {
  inventory_id: number | string;
  product_code: string;
  product_name: string;
  specification?: string;
  unit?: string;
  material_type?: MaterialType;
  quantity: number;
  available_quantity: number;
  reserved_quantity: number;
  safety_stock?: number;
  min_stock?: number;
  max_stock?: number;
  unit_cost?: number;
  sale_price?: number;
  inventory_value?: number;
  status: InventoryStatus;
  lot_number?: string;
  serial_number?: string;
  expiry_date?: Date | string;
  manufactured_date?: Date | string;
  warehouse?: number | string;
  warehouse_info?: { warehouse_name: string };
  location?: number | string;
  location_info?: { location_name: string };
  // 通用字段
  creator?: string;
  modifier?: string;
  create_time?: Date | string;
  update_time?: Date | string;
  is_deleted?: boolean;
  remark?: string;
  [key: string]: any;
}

/**
 * 库存交易记录类型
 */
export interface InventoryTransaction {
  transaction_id: number | string;
  transaction_type: string;
  product_code: string;
  product_name: string;
  quantity: number;
  unit_cost?: number;
  total_cost?: number;
  reference_document?: string;
  reference_type?: string;
  remark?: string;
  lot_number?: string;
  serial_number?: string;
  from_location?: number | string;
  to_location?: number | string;
  from_warehouse?: number | string;
  to_warehouse?: number | string;
  from_warehouse_name?: string;
  to_warehouse_name?: string;
  from_location_name?: string;
  to_location_name?: string;
  // 通用字段
  creator?: string;
  modifier?: string;
  create_time?: Date | string;
  update_time?: Date | string;
  is_deleted?: boolean;
  [key: string]: any;
}

/**
 * 库存搜索参数类型
 */
export interface InventorySearchParams {
  product_code?: string;
  product_name?: string;
  specification?: string;
  warehouse?: number | string;
  location?: number | string;
  status?: InventoryStatus;
  batch_number?: string;
  expiry_date_range?: [Date | undefined, Date | undefined];
  page_size?: number;
  page_num?: number;
  [key: string]: any;
}

/**
 * 库存调整参数类型
 */
export interface InventoryAdjustParams {
  inventory_id: number | string;
  adjust_quantity: number;
  reason: string;
  remark?: string;
  [key: string]: any;
}

/**
 * 库存移动参数类型
 */
export interface InventoryMoveParams {
  inventory_id: number | string;
  from_warehouse: number | string;
  from_location: number | string;
  to_warehouse: number | string;
  to_location: number | string;
  move_quantity: number;
  reason: string;
  remark?: string;
  [key: string]: any;
}

/**
 * 库存详情类型
 */
export interface InventoryDetail extends Inventory {
  // 扩展字段
}

/**
 * 表单字段配置类型
 */
export interface FormFieldConfig {
  field: string;
  component: string;
  label: string;
  componentProps?: Record<string, any>;
  colProps?: Record<string, any>;
  defaultValue?: any;
  validate?: {
    validator: any;
  };
  required?: boolean;
  [key: string]: any;
}

/**
 * 表格列配置类型
 */
export interface TableColumnConfig {
  type?: string;
  field: string;
  title: string;
  width?: number;
  align?: 'center' | 'left' | 'right';
  sortable?: boolean;
  fixed?: 'left' | 'right';
  formatter?: (row: any, column: any, value: any) => any;
  toolbarRender?: {
    slots: {
      default: (props: { row: any }) => any;
    };
  };
  [key: string]: any;
}
